home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / misc / vpan100.zip / SU_MAIN.CPP < prev    next >
C/C++ Source or Header  |  1995-01-19  |  10KB  |  339 lines

  1. //
  2. //         AC SUSCEPTEMETER
  3. //
  4. //         MAIN FUNCTION 
  5. //
  6. //                       |     Written by O.Rasizade
  7. //                 |       (c) Sept 1992, 1993
  8. //                       |
  9. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  10.  
  11. #include <vphead.h>    // must be included first
  12. #pragma hdrstop
  13.  
  14. #include <vpbase.h>
  15. #include <vpboard.h>
  16. #include <vpoutbox.h>
  17. #include <vpinbox.h>
  18. #include <vpindic.h>
  19. #include <vpgraph.h>
  20. #include <vpbutt.h>
  21. #include <vputil.h>
  22.  
  23. #include <suscept.h>
  24. #include "su_bp.h"
  25.  
  26.   int far EGAVGA_driver_far[1];
  27.  
  28. //+++++++++++++++++++++++++++++++++++++++++
  29. //++++++   GLOBAL VARIABLES +++++++++++++++
  30. //+++++++++++++++++++++++++++++++++++++++++
  31.  
  32.     //-------- POINTERS TO OBJECTS ----
  33. Indicator<double> *indTemp,*indInphase,*indOutphase;
  34. Indicator<double> *indDisbal,*indModule,*indR;
  35. TSInbox<int> *ptibDC, *ptibAC;
  36. Outbox *obxHelp;
  37. Board *Hysteresis,*Tdependance;
  38. indbutton *butHeater;
  39.  
  40. //+++++++++++++++++++++++++++++++++++++++++++++++++
  41. //++++++++++++++++++++ PROCEDURES +++++++++++++++++
  42. //+++++++++++++++++++++++++++++++++++++++++++++++++
  43.  
  44.  
  45. //------------------------------------- PRINT ABOUT -----
  46. #define LF_CR   gprintf_n(&xloc,&yloc,"")
  47.  
  48. void prnextr(int *xloc,int *yloc,char *text)
  49. {
  50.  setcolor(WHITE);
  51.  gprintf(*xloc-1,*yloc-1,text);
  52.  setcolor(DARKGRAY);
  53.   gprintf(*xloc+1,*yloc+1,text);
  54.  setcolor(LIGHTGRAY);
  55.   gprintf_n(xloc,yloc,text);
  56. }
  57. //--------------------
  58. void prnabout(int tfont)
  59. {
  60. int axl=maxxx>>1,ayl=maxyy>>1;
  61. int ax0=axl>>1,ay0=ayl>>1;
  62. int xloc=ax0,yloc=0;
  63. Board about(
  64.     x__xx(ax0),y__yy(ay0),    // left top coord where to paint the board
  65.     POPUP,            // may be FIXED,PERM,POPUP
  66.     "",                  // title
  67.     x__xx(axl),y__yy(ayl),        // size of board
  68.     procNULL,tfont,4);    // set font for first row
  69.  
  70.  about.Paint(); // is put here to release far heap before font
  71.  
  72.  setviewport(ax0,ay0,3*ax0,3*ay0,CLIP_OFF);
  73.  settextjustify(CENTER_TEXT,TOP_TEXT);
  74.  LF_CR;
  75.   prnextr(&xloc,&yloc,"A C");
  76.  settextstyle(tfont,HORIZ_DIR,3);
  77.   prnextr(&xloc,&yloc,"susceptometer");
  78.  settextstyle(tfont,HORIZ_DIR,2);
  79.   prnextr(&xloc,&yloc,"version 2.2");
  80.  settextstyle(0,HORIZ_DIR,1);
  81.  yloc+=10*yyspacing;
  82.  setcolor(LIGHTGREEN);
  83.   gprintf_n(&xloc,&yloc,"written by O.Rasizade");
  84.   gprintf_n(&xloc,&yloc,"");
  85.   gprintf_n(&xloc,&yloc,"Copyright NOSIR, 1992");
  86.  
  87.  getch();
  88.  about.Remove();
  89. }//-- END of PRINT ABOUT ----
  90.  
  91. //--------------------------- BACKGROUND PROCEDURE -----
  92. void  updateIndicators()
  93. {
  94.  indTemp->Refresh();
  95.  indInphase->Refresh();
  96.  indOutphase->Refresh();
  97.  if (indDisbal->OnScreen) indDisbal->Refresh();
  98.  if (indModule->OnScreen) indModule->Refresh();
  99.  if (indR->OnScreen)      indR->Refresh();
  100. }
  101.  
  102. //---------------------------------
  103. void far MainBackgr(void)
  104. {
  105. struct  time t;
  106. static int sec,hund;
  107.  
  108.  gettime(&t);
  109.  if (sec==t.ti_sec)
  110.    if ((t.ti_hund-hund)< 50)
  111.     return;
  112.  
  113.  double aa1=/*random(40000)/10.;*/ adc2volt((A1x8-ADC_ZERO*8)/8.); //@@@
  114.  double bb1=/*random(40000)/10.;*/ adc2volt((B1x8-ADC_ZERO*8)/8.); //@@@
  115.  a1=aa1*cosfi+bb1*sinfi; // balance
  116.  b1=-aa1*sinfi+bb1*cosfi;
  117.  module=sqrt(a1*a1+b1*b1);
  118.  if (a1!=0.0) { disbalance=atan2(b1,a1);}
  119.    else  { disbalance=M_PI_2;}
  120.  
  121.  Temp=/*random(2000)/10.;*/ MeasureTemp(&R);    //@@@
  122.  updateIndicators();
  123.  sec=t.ti_sec; hund=t.ti_hund;
  124.  if (errCodeISR) errExit();
  125. }
  126. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  127. //++++++++++++++++++++++++ MAIN+++++++++++++++++++++++++++++++++
  128. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  129. main()
  130. {
  131. InitAndCopyright("* AC Susceptometer * Copyright (c) O.Rasizade, 1992, LNP, tel.66135 *");
  132. prnabout(TRIPLEX_FONT);
  133.  
  134. butsystem bsMain(MASTER);
  135.  
  136.         //---------- TEMPERATURE INDICATOR ------
  137. Indicator<double>
  138.     _indTemp(0,0,FIXED,"Temperature",    // title
  139.         10, &Temp,"%.2f K",// width of disp in chars,format
  140.         UNFRAMED,procDummy,
  141.         0,1,        //font and size of number
  142.         SMALL_FONT,4);    //font and size of title
  143.             //plaquecoldflt,LCDbright);
  144.  
  145.         //-------- AREA FOR MOVING OBJECTS IS DEFINED ------
  146.  
  147. xxmaxs=maxxx-_indTemp.xxmax+_indTemp.xx0-4;    xmaxs=x__xx(xxmaxs);
  148. ymaxs=maxy-30;                     yymaxs=yy__y(ymaxs);
  149. _indTemp.MovetoXY(xmaxs+2,y0s+2);
  150.  
  151.            //-------------- VERTICAL PANEL ------
  152. Board PanelVert(xmaxs+1,y0s,FIXED,"",
  153.         maxx-xmaxs-1,maxy-y0s);    // size of board
  154.  
  155.         //---------- INPHASE VOLTAGE INDICATOR ------
  156. Indicator<double>
  157.     _indInphase(xmaxs+2,_indTemp.ymax,FIXED,"In Phase",
  158.         10, &a1,"%.2f V",    // width of disp in chars,format
  159.         UNFRAMED,procDummy,
  160.         0,1,        //font and size of number
  161.         SMALL_FONT,4),    //font and size of title
  162.  
  163.         //---------- OUTPHASE VOLTAGE INDICATOR ------
  164.    _indOutphase(xmaxs+2,_indInphase.ymax,FIXED,"Out Phase",
  165.         10, &b1,"%.2f V",    // width of disp in chars,format
  166.         UNFRAMED,procDummy,
  167.         0,1,        //font and size of number
  168.         SMALL_FONT,4);    //font and size of title
  169.  
  170. indTemp=&_indTemp;
  171. indInphase=&_indInphase;
  172. indOutphase=&_indOutphase;
  173.  
  174. PanelVert.Paint();
  175. _indTemp.Paint();
  176. _indInphase.Paint();
  177. _indOutphase.Paint();
  178.  
  179.     //------------- COMMON BAR PARAMETERS ------
  180. #define heatIND_R     4    // radius of LED
  181.  
  182. #define butFONT       SMALL_FONT
  183. #define butFONT_SIZE    4
  184.  
  185. #define barFONT       SMALL_FONT
  186. #define barFONT_SIZE    4
  187. #define barBORDER_Y    4 // dist. between low border of bar and last button
  188.  
  189. int bar_xx0=xx__x(PanelVert.x0+SHADWIDTH+4),
  190.     bar_xxmax=xx__x(PanelVert.xmax-SHADWIDTH-4);
  191.  
  192.     //------------ CAMAC CONTROLS -------
  193.  
  194. const int barCam_yy0=_indOutphase.yymax;
  195. settextstyle(barFONT, HORIZ_DIR, barFONT_SIZE);
  196.  
  197. //-------- AC -----
  198. const outboxcolors ibxcolLum1={
  199.                YELLOW,        // color of title
  200.                LIGHTGREEN,    // text color
  201.                YELLOW,        // high-lighted text
  202.                BLACK            // color of paper
  203.                };
  204.  
  205.  ptibAC = new TSInbox<int>
  206.      (bar_xx0,_indOutphase.ymax+y__yy(textheight("p"))+4*SPACING,
  207.      "AC(0..255):", 6, &altI,// width of disp in chars, variable
  208.       "%d","%d",    // scan and print format
  209.       setAltI, SMALL_FONT, 4,plaquecoldflt,ibxcolLum1);
  210. //-------- DC -----
  211.  ptibDC = new TSInbox<int>
  212.      (bar_xx0, ptibAC->ymax, "DC(-511..512):",
  213.       6, &constI,    // width of disp in chars,variable
  214.       "%d","%d",    // scan and print format
  215.       setConstI, SMALL_FONT, 4,plaquecoldflt,ibxcolLum1);
  216.  
  217. butgrp CamCtrl( bar_xx0+2*INDOFFSET+2*heatIND_R, ptibDC->ymax,
  218.         60,18,VERT,0);
  219.   button butEnterBal("Balance",'B','b',bpEnterBal,butFONT,butFONT_SIZE);
  220.   indbutton _butHeater("Heater",'H','h',bpHeater,heatIND_R,butFONT,butFONT_SIZE);
  221.   button butGain("Gain",'G','g',bpGain,butFONT,butFONT_SIZE);
  222.  
  223. butHeater=&_butHeater;
  224. const int barCam_yymax=butGain.yymax+yy__y(barBORDER_Y);
  225.  
  226.     //---------- PAINT CAMAC CTRL PANEL -----
  227. maxviewport;
  228. setfillstyle(SOLID_FILL,BLUE);
  229. bar(bar_xx0,barCam_yy0,bar_xxmax,barCam_yymax);
  230. setcolor(LIGHTGRAY);
  231. settextjustify(LEFT_TEXT,TOP_TEXT);
  232. outtextxy(bar_xx0,barCam_yy0+yyspacing," CAMAC control");
  233. ptibAC->Paint();
  234. ptibDC->Paint();
  235. ptibAC->Refresh();
  236. ptibDC->Refresh();
  237. CamCtrl.Paint();
  238.  
  239.         //-------------------- DISPLAY BUTTONS -------
  240. const int barDisp_yy0=barCam_yymax+yy__y(16);
  241. settextstyle(barFONT, HORIZ_DIR, barFONT_SIZE);
  242.  
  243. butgrp bgrDisp( bar_xx0+2*INDOFFSET+2*heatIND_R,
  244.         y__yy(barDisp_yy0+textheight("p"))+4*SPACING,
  245.         60,18,VERT,0);
  246.   button butR("R",'R','r',bpR,butFONT,butFONT_SIZE);
  247.   button butModule("Module",'M','m',bpModule,butFONT,butFONT_SIZE);
  248.   button butDisbal("disBal",'B','b',bpDisbal,butFONT,butFONT_SIZE);
  249.  
  250. const int barDisp_yymax=butDisbal.yymax+yy__y(barBORDER_Y);
  251.  
  252.     //------- PAINT DISPLAY PANEL -----
  253. setfillstyle(SOLID_FILL,BLUE);
  254. maxviewport;
  255. bar(bar_xx0,barDisp_yy0,bar_xxmax,barDisp_yymax);
  256. setcolor(LIGHTGRAY);
  257. settextjustify(LEFT_TEXT,TOP_TEXT);
  258. outtextxy(bar_xx0,barDisp_yy0+yyspacing," Display");
  259. bgrDisp.Paint();
  260.  
  261.     //------ DISPLAY INDICATORS --------
  262. Indicator<double>
  263. //----- DISBALANCE -----
  264.    _indDisbal(x0s,y0s,PERM,"Disbalance",
  265.       12, &disbalance,"%.3lf rad",    // width of disp in chars,format
  266.       FRAMED,ppDisbal,
  267.       0,1),                   //font and size of number
  268.  
  269. //-------- R -----
  270.    _indR(x0s,y0s,PERM,"Thermo R",
  271.       12, &R,"%.4lf K",    // width of disp in chars,format
  272.       FRAMED,ppR,
  273.       0,1),        //font and size of number
  274.  
  275. //----- MODULE -----
  276.    _indModule(x0s,y0s,PERM,"Module",
  277.       12, &module,"%.3lf",    // width of disp in chars,format
  278.       FRAMED,ppModule,
  279.       0,1);                   //font and size of number
  280.  
  281. indR=&_indR;
  282. indModule=&_indModule;
  283. indDisbal=&_indDisbal;
  284.  
  285.         //----------------- HELP ------
  286.  
  287. Outbox _obxHelp(maxx>>2,maxy>>2,POPUP,"Help",
  288.          35,10,        // size of board
  289.          FRAMED,
  290.          bpHelp,3,4);    // title font
  291. obxHelp=&_obxHelp;
  292.  
  293.         //----------- HYSTERESIS PANEL ------
  294. Board _Hysteresis(x0s,y0s,POPUP,"Hysteresis measurement",
  295.           0,0,bpHyst,// size of board
  296.           HYST_TITLE_FONT,HYST_TITLE_FONT_SIZE);
  297. Hysteresis=&_Hysteresis;
  298.  
  299.         //----------- T-DEPENDANCE PANEL ------
  300. Board _Tdependance(x0s,y0s,POPUP,"T-dep. measurement",
  301.           0,0,bpTdep,// size of board
  302.           HYST_TITLE_FONT,HYST_TITLE_FONT_SIZE);
  303. Tdependance=&_Tdependance;
  304.  
  305.  
  306.         //---------- HORIZONTAL BUTTONS -------
  307.  
  308. Board PanelHoriz(0,ymaxs+1,FIXED,"",xmaxs,maxy-ymaxs-1/*size of board*/);
  309.  
  310. butgrp HorizButtons(3,maxy-25,70,21,HORIZ,2);
  311.  button butQuit("Quit",'Q','q',bpQuit,0,1,quittexcol,quitbutcol);
  312.  button butHelp("Help",'h','H',bpHelp);
  313.   HorizButtons.ShiftX(10);
  314.  button butHyst("hYster",'Y','y',bpHyst);
  315.  button butHystGraph("Graph",'G','g',bpHystGraph);
  316.   HorizButtons.ShiftX(10);
  317.  button butTdep("T-dep",'T','t',bpTdep);
  318.  button butTdepGraph("gRaph",'R','r',bpTdepGraph);
  319.  
  320.  
  321. PanelHoriz.Paint();
  322. HorizButtons.Paint();
  323.  
  324.         //---------- PROGRAM ---------
  325.  InitCamac();
  326.  InitSuscept();
  327.  camEnInt();
  328.  
  329.  bsMain.NextButton();
  330.  bsMain.NextButton();
  331.  
  332.  object::LoadCnfg(CNF_NAME);
  333.  object::RepaintScr();
  334.  
  335.  bsMain.Loop(MainBackgr);
  336.  bpQuit();
  337. }
  338. //++++++++++++++++++++++++ END OF MAIN ++++++++++++++++++++++++
  339.